import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

/**
 * 编写页面处理类
 */
public class myprocessor implements PageProcessor {
    public void process(Page page) {
//        System.out.println(page.getHtml().xpath("//*[@id=\"nav\"]/div/div/ul/li[3]/a").toString());
//        System.out.println(page.getHtml().xpath("//*[@id=\"nav\"]/div/div/ul/li[3]/a/text()").toString());

        page.addTargetRequests(page.getHtml().links().all());
        ////*[@id="nav"]/div/div/ul/li[12]/a
        ////*[@id="nav"]/div/div/ul/li[4]/a
        System.out.println(page.getHtml().xpath("//*[@id=\"nav\"]/div/div/ul/li[12]/a/text()").toString());
    }

    public Site getSite() {
        //配置站点信息
        return Site.me()
                .setRetryTimes(3 )
                .setSleepTime(2000);
    }

    public static void main(String[] args) {
        Spider.create(new myprocessor())
                .addUrl("https://www.csdn.net/")
                .run();
        System.out.println("remote add");        
    }
}
